
local hanshi = fk.CreateSkill {
  name = "lingling__hanshi",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__hanshi"] = "寒士",
  [":lingling__hanshi"] = "锁定技，冰【杀】对你无效。当你受到伤害后，你令一名角色将两张牌当冰【杀】使用。",

  ["#lingling__hanshi-choose"] = "寒士：令一名角色将两张牌当冰【杀】使用",
  ["#lingling__hanshi-use"] = "寒士：请将两张牌当冰【杀】使用",
}

hanshi:addEffect(fk.PreCardEffect, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hanshi.name) and data.card.name == "ice__slash" and data.to == player
  end,
  on_use = function (self, event, target, player, data)
    data.nullified = true
  end,
})

hanshi:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hanshi.name) and
      table.find(player.room.alive_players, function (p)
        return #p:getCardIds("e") + #p:getHandlyIds() > 1 and
          p:canUse(Fk:cloneCard("ice__slash"), { bypass_times = true })
      end)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return #p:getCardIds("e") + #p:getHandlyIds() > 1 and
        p:canUse(Fk:cloneCard("ice__slash"), { bypass_times = true })
      end)
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = hanshi.name,
      prompt = "#lingling__hanshi-choose",
      cancelable = false,
    })[1]
    room:askToUseVirtualCard(to, {
      name = "ice__slash",
      skill_name = hanshi.name,
      prompt = "#lingling__hanshi-use",
      cancelable = false,
      extra_data = {
        bypass_times = true,
        extraUse = true,
      },
      card_filter = {
        n = 2,
      },
    })
  end,
})

return hanshi
